home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
283_01
/
fafnir.h
< prev
next >
Wrap
Text File
|
1988-12-08
|
20KB
|
572 lines
/* fafnir.h -- general purpose forms dragon, with Elysian Fields
5/10/88, 8/20/88, 9/10/88, 9/24/88, by d.c.oshel
*/
/*========================================================================*
** A FORM_RULES array defines a form. **
** **
** All relevant information about a form and its fields is collected in **
** the field elements of a FORM_RULES array. **
*========================================================================*/
typedef char * FPTR; /* pointer to a character array used for data entry */
#define FIELDS FPTR /* for convenience in declaring field names */
typedef int (cdecl * VALIDATER)(); /* pointer to C function returning int */
#define VNOP ((VALIDATER)0) /* "null function", validate not required */
/* NOTE: character validaters: unsigned (*cv)( unsigned ch, int position );
field validaters: int (*fv)( char *p, int x, int y, int len );
field initializers: int (*fi)( char *p, int x, int y, int len );
*/
typedef struct field_element {
FPTR *fptr; /* the ADDRESS of a char * to this field's storage area */
FPTR dflt; /* pointer to a default data entry mask for this field */
int x; /* screen column of field, 0..79 */
int y; /* screen line of field, 0..24 */
int len; /* field width; if negative, width of window & field = 80 */
VALIDATER fi; /* pointer to each-time-arrived field initializer */
/* if fi == VNOP, the field is not touched */
VALIDATER cv; /* pointer to character-by-character validation function */
/* if cv == VNOP, the cursor does not stop in the field */
VALIDATER fv; /* pointer to each-time-exited field validation function */
/* if fv == VNOP, the field is considered valid */
} FORM_RULES;
/* see EditField concerning variable length fields (len < 0), below */
/*======================================================================*/
/* FORM_RULES macros for standard field types */
/*======================================================================*/
#define MAXVFLDLEN 80 /* longest variable length field */
#define SLIDE(L) (-L) /* marks window width for variable length field */
#define DEFINE_FIELDS(Q) FORM_RULES Q[] = {
#define END_FIELDS };
#define GetPage(SCREEN,NAME,OFFSET,NUMFLZ) SCREEN,&NAME[OFFSET],NUMFLZ
#define FormSize(F) (sizeof(F)/sizeof(FORM_RULES))
/* default edit masks */
#define TX_MASK NULL /* text */
#define DL_MASK zdol /* dollar */
#define PH_MASK zfone /* phone */
#define DT_MASK zdate /* date */
#define SN_MASK zssn /* social security number */
#define ZR_MASK zeroes /* all zeroes */
#define YN_MASK "N" /* Yes or No */
#define DL_SIZE 15
#define PH_SIZE 14
#define SN_SIZE 11
#define TZ_SIZE 10
#define DT_SIZE 8
#define ZP_SIZE 5
#define YN_SIZE 1
#define TF_SIZE YN_SIZE
#define ST_SIZE 2
#define CO_SIZE 2
#define TOP_OF_FORM 0
#define UPDATE 1 /* see Example, below */
#define ADD 0 /* see Example, below */
/* the following macros reduce the field definition task to simple lists */
#define FIELD(F,M,X,Y,L,I,C,V) {&F,M,X,Y,L,I,C,V}, /* generic macro */
/*------------------------------------------*/
/* F field name */
/* M default field mask, i.e., contents */
/* X screen column */
/* Y screen row */
/* L field length, i.e., width */
/* I field initialization, VALIDATER name */
/* C character validation, VALIDATER name */
/* V field validation, VALIDATER name */
/*------------------------------------------*/
/* Example of editing a prior record:
*
* FIELDS lastname, firstnam, fullname, homephon;
*
* DEFINE_FIELDS( edits_record )
* TEXT( lastname, 10, 2, 15 )
* TEXT( firstnam, 10, 3, 15 )
* VIRTUAL( fullname, 10, 5, 30, concatnames )
* PHONE_SET( homephon, "(319) 555- ", 10, 7 )
* END_FIELDS;
*
* #define ALL 4
*
* AllocateFields( edits_record, ALL );
* <--find previous record and load fields because UPDATE-->
* action = OnePageForm(
* GetPage( edits_record, TOPF, ALL_FIELDS ),
* UPDATE
* );
* <--save/ignore edits, etc., based on action-->
* ReleaseFields( edits_record, ALL );
*/
/* Note macro syntax: use "NAME( ", not "NAME ("
* do not put trailing commas after ) in field type macros.
*/
/* WARNING: the NumFields dimension is ** CRITICAL **
* in AllocateFields! Potential system crash.
*/
/* WARNING: routines to load fields must pad right
* with blanks, and honor field width!
*/
/* standard text field definitions */
#define TEXT(F,X,Y,L) {&F,TX_MASK,X,Y,L,VNOP,cgood,VNOP},
#define UPPER(F,X,Y,L) {&F,TX_MASK,X,Y,L,VNOP,c2upr,VNOP},
#define TEXT_SET(F,M,X,Y,L) {&F,M,X,Y,L,VNOP,cgood,VNOP},
#define UPPER_SET(F,M,X,Y,L) {&F,M,X,Y,L,VNOP,c2upr,VNOP},
/* masked numeric input, L <= 10, R is a VALIDATER for range checking */
#define ZERO(F,X,Y,L,R) {&F,ZR_MASK,X,Y,L,VNOP,cnmrc,R},
#define ZERO_SET(F,M,X,Y,L,R) {&F,M,X,Y,L,VNOP,cnmrc,R},
/* standard fields with pre-determined widths */
#define DOLLAR(F,X,Y) {&F,DL_MASK,X,Y,DL_SIZE,lj_dol,cdoll,rj_dol},
#define PHONE(F,X,Y) {&F,PH_MASK,X,Y,PH_SIZE,VNOP,cfone,VNOP},
#define SSN(F,X,Y) {&F,SN_MASK,X,Y,SN_SIZE,VNOP,cnmrc,VNOP},
#define DATE(F,X,Y) {&F,DT_MASK,X,Y,DT_SIZE,VNOP,cnmrc,vdate},
#define ZIP(F,X,Y) {&F,ZP_MASK,X,Y,YN_SIZE,VNOP,cnmrc,VNOP},
#define TENZIP(F,X,Y) {&F,TZ_MASK,X,Y,TZ_SIZE,VNOP,cnzip,VNOP},
#define YESNO(F,X,Y) {&F,"Y",X,Y,TF_SIZE,VNOP,ctfyn,vtrufal},
#define NOYES(F,X,Y) {&F,"N",X,Y,TF_SIZE,VNOP,ctfyn,vtrufal},
#define DOLLAR_SET(F,M,X,Y) {&F,M,X,Y,DL_SIZE,lj_dol,cdoll,rj_dol},
#define PHONE_SET(F,M,X,Y) {&F,M,X,Y,PH_SIZE,VNOP,cfone,VNOP},
#define SSN_SET(F,M,X,Y) {&F,M,X,Y,SN_SIZE,VNOP,cnmrc,VNOP},
#define DATE_SET(F,M,X,Y) {&F,M,X,Y,DT_SIZE,VNOP,cnmrc,vdate},
#define ZIP_SET(F,M,X,Y) {&F,M,X,Y,YN_SIZE,VNOP,cnmrc,VNOP},
#define TENZIP_SET(F,M,X,Y) {&F,M,X,Y,TZ_SIZE,VNOP,cnzip,VNOP},
/* standard two-letter U.S. state and territory abbreviations */
#define STATE_SET(F,M,X,Y) {&F,M,X,Y,ST_SIZE,VNOP,c2upr,vstate},
/* Iowa Dept. of Transportation numeric county codes */
#define COUNTY_SET(F,M,X,Y) {&F,M,X,Y,CO_SIZE,VNOP,cnmrc,vcounty},
/* information-only field types */
#define TODAY(F,X,Y) {&F,NULL,X,Y,DT_SIZE,vtoday,VNOP,VNOP},
#define DISPLAY(F,X,Y,L) {&F,NULL,X,Y,L,VNOP,VNOP,VNOP},
#define VIRTUAL(F,X,Y,L,A) {&F,NULL,X,Y,L,A,VNOP,VNOP}, /* (*fi)() does it! */
#define COMPUTE(F,X,Y,L,B) {&F,NULL,X,Y,L,VNOP,VNOP,B}, /* (*fv)() does it! */
#define DISPLAY_SET(F,M,X,Y,L) {&F,M,X,Y,L,VNOP,VNOP,VNOP},
#define VIRTUAL_SET(F,M,X,Y,L,A) {&F,M,X,Y,L,A,VNOP,VNOP}, /* (*fi)() does it! */
#define COMPUTE_SET(F,M,X,Y,L,B) {&F,M,X,Y,L,VNOP,VNOP,B}, /* (*fv)() does it! */
/* INITIALIZE is a dummy (and costly!) secondary reference to a field.
The idea is to get a field which is not immediately used into the range
of fields allocated and/or initialized by AllocateFields or In